﻿using RabbitMQ.Client;
using System.Text;
using Zhaoxi.MessageProducer.Exchanges;

try
{
    Console.WriteLine("================生产者====================");
    Console.WriteLine("================生产者====================");
    Console.WriteLine("================生产者====================");

    #region 20230504
    //{

    //    //一、nuget引入操作rabbitMQ的程序包：RabbitMQ.Client

    //    string dir = AppDomain.CurrentDomain.BaseDirectory;
    //    ////当前生产者名称
    //    string? producerName = Path.GetFileName(Path.GetDirectoryName(dir));
    //    //消费者


    //    ConnectionFactory factory = new ConnectionFactory(); //创建链接的工厂
    //    factory.HostName = "43.142.250.100";//RabbitMQ服务在本地运行
    //    factory.UserName = "guest";//用户名
    //    factory.Password = "guest";//密码  
    //    factory.Port = 5672; //程序调用默认的端口是：5672

    //    using (IConnection connection = factory.CreateConnection()) //创建链接
    //    {
    //        using (IModel channel = connection.CreateModel()) //创建信道  --高速公路---单车道
    //        {
    //            //创建一个队列---检查队列是否存在，如果不存在就创建出来；
    //            channel.QueueDeclare(queue: "OnlyProducerMessage", durable: true, exclusive: false, autoDelete: false, arguments: null);

    //            //创建一个交换机
    //            channel.ExchangeDeclare(exchange: "OnlyProducerMessageExChange", type: ExchangeType.Direct, durable: true, autoDelete: false, arguments: null);


    //            channel.QueueBind(queue: "OnlyProducerMessage", exchange: "OnlyProducerMessageExChange", routingKey: string.Empty, arguments: null);

    //            Console.ForegroundColor = ConsoleColor.Red;
    //            Console.WriteLine($"=========生产者:{producerName} 已准备就绪=========");
    //            int i = 1;
    //            {
    //                while (true)
    //                {
    //                    string message = $"{producerName} : 和Richard一起走学习.NET技术_{i}";

    //                    byte[] body = Encoding.UTF8.GetBytes(message);

    //                    channel.BasicPublish(exchange: "OnlyProducerMessageExChange",
    //                                    routingKey: string.Empty,
    //                                    basicProperties: null,
    //                                    body: body);
    //                    Console.WriteLine($"=========消息：{message} 已发送=========");
    //                    i++;
    //                    Thread.Sleep(500);
    //                }
    //            }
    //        }
    //    }
    //}
    #endregion

    #region 20230505
    {
        // DirectExchange.Show();
        // FanoutExchange.Show(); 
         TopicExchange.Show();
    }
    #endregion

}
catch (Exception ex)
{
    Console.WriteLine(ex.Message);
}